BP1 Plugin Description

This plugin implements a modified BackPropagation neural network plus a basic graph drawing routine. The plugin validates user commands and returns appropriate error messages to aid diagnostics.

The BP1 plugin is implemented using HyperNext to control the validation and user input/output functions while RBscript implements the BP neural network algorithm.

Further information regarding the HyperNext ~ RBscript neural network interface can be found in the Language Reference.


Plugin Usage

(1) Initialisation

The following is an example of how to initialise the plugin. This causes the plugin to compile itself and return an error number, zero indicates successful initialisation. 

   Global pluginOkay,errNum

   Call BP1_PI.Init(1)

   Put BP1_PI.errNum into errNum

   If errNum=0 Then
       Put 1 into pluginOkay
       Put 'okay' into field 1
   Else
       Put 0 into pluginOkay
       Put 'error' into field 1
   EndIf


Note that the Init call takes a canvas number as a parameter. This canvas is used by the plugin both as the backdrop for the graphing utility and for the neural network interface with RBscript and HyperNext.



(2) Training example

This shows a complete routine for setting up the graph, the neural network specification, the learning parameters, the training data, the training specification and the commands controlling the neural network operation.

------------------------------------------------------------------------
    Global pluginOkay,trainedOkay
   Global dataSet,dataLoaded
   Global normData

   Global maxSteps,skipValue,netError,randSeed
   Global netEta,netAlpha,netFunc

   Global numInputs,numOutputs,numHidden

   Local sdata,glist

   If (pluginOkay=1) AND (dataLoaded=1) Then

       @ *** Graph - name, plots == plot four input errors.
       Put 4 into glist
       Put 1 after glist
       Put 2 after glist
       Put 3 after glist
       Put 4 after glist
       Call BP1_PI.SetGraphSpec('Heart Data',2,1,glist)

       @ *** Neural Net physical - IPs, OPs, FuncType, Hidden List
       Call BP1_PI.SetNeuralSpec(12,1,netFunc,'1,12')

       @ *** Learning - eta,alpha
       Call BP1_PI.SetLearnSpec(netEta,netAlpha)

       @ *** Weights - train=1, query=2, load, rnd seed
       Call BP1_PI.SetCommand(1,0,randSeed)

       @ *** Training Data - data
       Call BP1_PI.SetTrainingData(dataSet)

       @ *** Training Spec - yield, graph, skip, maxsteps, tolerance,log
       Call BP1_PI.SetTrainSpec(1,1,skipValue,maxSteps,netError,0)

       Call BP1_PI.TrainNetwork

       Put RBsOutputFN into field 1
       Put 1 into trainedOkay
   Else
       If pluginOkay=0 Then
           Message 'Plugin not initialised or faulty'
       Else
           Message 'Training data not loaded!'
       EndIf
   EndIf
---------------------------------------------------------------------

1/ Graph Specification

The graph is specified with the following call

    Call BP1_PI.SetGraphSpec(name,error,caption,glist)

   where

         name - the graph's title as in "Heart data"

         error - the maximum height of the y axis

         caption flag - whether the caption box is shown or not.
                        this is used in conjunction with glist.

         glist - specifies whether or not a set of input errors are plotted
                 the format is
                               1st line - flag, if zero no plots, other wise number of plots.
																															2nd line - identity of the first input plot, i.e 6 = 6th input plotted.
																															3rd line -    "   second input plot.


Note, the length of the x axis is specified in the SetTrainSpec command.


2/ Neural Network Size

This sets the physical size of the neural network, including its weight matrix.

       @ *** Neural Net physical - IPs, OPs, FuncType, Hidden List
       Call BP1_PI.SetNeuralSpec(12,1,netFunc,'1,12')

			Where

         IPs - number of inputs
         OPs - number of outputs
         FuncType - function type, 1 - sigmoid, 2 - tanh.
         Hidden neurons - number of hidden neurons.



3/ Neural Network learning

Sets the learning parameters - the learning rate and the momentum.

       @ *** Learning - eta,alpha
       Call BP1_PI.SetLearnSpec(netEta,netAlpha)




4/ Initialise Neural Network

This specifies how the neural network should be initialised and operated.
After training wht weight matrix is automatically saved and can be accessed from HyperNext using the function RBsWeightsFN and modified using the procedure RBsSetWeights as described in the Language Reference.

       @ *** Weights - train=1, query=2, load, rnd seed
       Call BP1_PI.SetCommand(1,0,randSeed)
   
   where
         train - train or query, 1 = train network, 2 - query network
         load - load the saved weight matrix, 1 = load, 0 do not load
         randseed - a number specifying how the weight matrix should be randomised.
                    if the weight matrix is loaded then randomisation is ignored
                    otherwise, 0 uses the current time to set the seed, and non zero becomes the seed.

Note,
 when testing the neural network the load flag should be set to 1.



5/ Training Data

Sets the training data using the specified variable.

    @ *** Training Data - data
    Call BP1_PI.SetTrainingData(dataSet)

The dataset has the form

  1st line - number of samples in the dataset.
  2nd line - column titles separedt by commas
  3rd line - 1st sample in the dataset
             each sample has n inputs plus m outputs all comma separated.
  4th line - 2nd sample



6/ Training Specification

Sets up the training regime.

    @ *** Training Spec - yield, graph, skip, maxsteps, tolerance,log
    Call BP1_PI.SetTrainSpec(1,1,skipValue,maxSteps,netError,0)

   where

       yield - whether the neural network can be aborted using the escape key
               0 - do not yield, 1 yield.
       graph - whether to display the graph
               0 - do not display, 1 - display.
       skipvalue - whether drawing the graphing and checking the escape key should be skipped or not.
                   0 - do not skip and draw every time step
                   n - draw graph and check escape key every n timesteps.
       maxsteps - train over a maximum of maxsteps steps.
                  when maxtseps is reached the training is terminated, even if convergence has failed.
       net error - the mean global error when convergence is considered to have been achieved
                   usually, 0.1 or thereabouts.
       log - whether to log the error in each input as training progresses.
             0 - do not log, 1 - log
             the log can be accessed using the RBsLogFN function.
             The log is made at each skip value.



7/ Train Network Command

Starts the neural network training.

    Call BP1_PI.TrainNetwork


8/ Query Network Command

Queries the neural network over the entire test data set.

    Call BP1_PI.QueryNetwork




Neural Network Output

The neural network's response or analysis is accessed using the function RBsResultsFN.
This lists each output value in response to the testing dataset.
For instance, if the neural network has 5 outputs and there where 1000 samples in the testing dataset then the list would comprise 1000 lines with each line having 5 real numeric values separated by commas.


Further information regarding the HyperNext ~ RBscript neural network interface can be found in the Language Reference.

